/* -----------------------------------------------------------------------
 * Don't forget to include the following lines in your makefile:
 *
 * testFileName: testFileName.c dominion.o rngs.o
 *      gcc -o testFileName -g  testFileName.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 *
 *  unittest4 tests the isGameOver() function
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
//#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

int main() {
    int i;
    int seed = 1;
    int numPlayer = 2;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G, J;

#if (NOISY_TEST == 1)
        printf("Testing isGameOver() function...\n");
#endif

    int game1 = initializeGame(numPlayer, k, seed, &G);
    assert(game1 == 0);
    assert(isGameOver(&G) == 0);

    int game2 = initializeGame(numPlayer, k, seed, &J);
    assert(game2 == 0);
    assert(isGameOver(&J) == 0);

#if (NOISY_TEST == 1)
        printf("Game successfully initialized!\n");
#endif

#if (NOISY_TEST == 1)
        printf("Checking kingdom cards...\n");
#endif

    for(i = 0; i < 10; i++){
        G.supplyCount[adventurer]--;
        assert(isGameOver(&G) == 0);
    }

    for(i = 0; i < 10; i++){
        G.supplyCount[feast]--;
        assert(isGameOver(&G) == 0);
    }

    for(i = 0; i < 9; i++){
        G.supplyCount[mine]--;
        assert(isGameOver(&G) == 0);
    }

    G.supplyCount[mine]--;
    assert(isGameOver(&G) == 1);

#if (NOISY_TEST == 1)
        printf("Kingdom cards success!\n");
#endif

#if (NOISY_TEST == 1)
        printf("Checking province cards...\n");
#endif

    for(i = 0; i < 7; i++){
        J.supplyCount[province]--;
        assert(isGameOver(&J) == 0);
    }

    J.supplyCount[province]--;
    assert(isGameOver(&J) == 1);

#if (NOISY_TEST == 1)
        printf("Province cards success!\n");
        printf("All tests passed! Game Over!!!!\n");
#endif

    return 0;
}
